using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace View
{
	/// <summary>
	/// Summary description for AddAccountDialog.
	/// </summary>
	public class AddAccountDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label Label1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.TextBox AcctNametextBox1;
		private System.Windows.Forms.TextBox AcctBalancetextBox2;
		private System.Windows.Forms.TextBox WebsitetextBox1;
		private System.Windows.Forms.TextBox CreditLimittextBox1;
		private System.Windows.Forms.Label Limitlabel4;
		private System.Windows.Forms.Label Websitelabel5;
		Model.UserManager manager;
		private PinkieControls.ButtonXP addAccountButton;
		private PinkieControls.ButtonXP cancelButton;
		
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AddAccountDialog(Model.UserManager mymanager)
		{
			
			manager =mymanager;
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			Limitlabel4.Hide();
			CreditLimittextBox1.Hide();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.Limitlabel4 = new System.Windows.Forms.Label();
			this.Websitelabel5 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.AcctNametextBox1 = new System.Windows.Forms.TextBox();
			this.AcctBalancetextBox2 = new System.Windows.Forms.TextBox();
			this.WebsitetextBox1 = new System.Windows.Forms.TextBox();
			this.CreditLimittextBox1 = new System.Windows.Forms.TextBox();
			this.addAccountButton = new PinkieControls.ButtonXP();
			this.cancelButton = new PinkieControls.ButtonXP();
			this.SuspendLayout();
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(16, 24);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(80, 16);
			this.Label1.TabIndex = 0;
			this.Label1.Text = "Account Type:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(88, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "Account Name:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 88);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(88, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "Balance:";
			// 
			// Limitlabel4
			// 
			this.Limitlabel4.Location = new System.Drawing.Point(16, 120);
			this.Limitlabel4.Name = "Limitlabel4";
			this.Limitlabel4.Size = new System.Drawing.Size(88, 16);
			this.Limitlabel4.TabIndex = 3;
			this.Limitlabel4.Text = "Credit Limit:";
			this.Limitlabel4.Click += new System.EventHandler(this.label4_Click);
			// 
			// Websitelabel5
			// 
			this.Websitelabel5.Location = new System.Drawing.Point(16, 120);
			this.Websitelabel5.Name = "Websitelabel5";
			this.Websitelabel5.Size = new System.Drawing.Size(100, 16);
			this.Websitelabel5.TabIndex = 3;
			this.Websitelabel5.Text = "Account Website:";
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "Bank Account",
														   "Credit Card"});
			this.comboBox1.Location = new System.Drawing.Point(120, 24);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.SelectedIndex = 0;
			this.comboBox1.Size = new System.Drawing.Size(144, 21);
			this.comboBox1.TabIndex = 4;
			this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
			// 
			// AcctNametextBox1
			// 
			this.AcctNametextBox1.Location = new System.Drawing.Point(120, 56);
			this.AcctNametextBox1.Name = "AcctNametextBox1";
			this.AcctNametextBox1.Size = new System.Drawing.Size(144, 20);
			this.AcctNametextBox1.TabIndex = 5;
			this.AcctNametextBox1.Text = "";
			// 
			// AcctBalancetextBox2
			// 
			this.AcctBalancetextBox2.Location = new System.Drawing.Point(120, 88);
			this.AcctBalancetextBox2.Name = "AcctBalancetextBox2";
			this.AcctBalancetextBox2.Size = new System.Drawing.Size(144, 20);
			this.AcctBalancetextBox2.TabIndex = 6;
			this.AcctBalancetextBox2.Text = "";
			// 
			// WebsitetextBox1
			// 
			this.WebsitetextBox1.Location = new System.Drawing.Point(120, 120);
			this.WebsitetextBox1.Name = "WebsitetextBox1";
			this.WebsitetextBox1.Size = new System.Drawing.Size(144, 20);
			this.WebsitetextBox1.TabIndex = 6;
			this.WebsitetextBox1.Text = "http://";
			// 
			// CreditLimittextBox1
			// 
			this.CreditLimittextBox1.Location = new System.Drawing.Point(120, 120);
			this.CreditLimittextBox1.Name = "CreditLimittextBox1";
			this.CreditLimittextBox1.Size = new System.Drawing.Size(144, 20);
			this.CreditLimittextBox1.TabIndex = 6;
			this.CreditLimittextBox1.Text = "";
			// 
			// addAccountButton
			// 
			this.addAccountButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(224)), ((System.Byte)(223)), ((System.Byte)(227)));
			this.addAccountButton.DefaultScheme = true;
			this.addAccountButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.addAccountButton.Hint = "";
			this.addAccountButton.Location = new System.Drawing.Point(56, 160);
			this.addAccountButton.Name = "addAccountButton";
			this.addAccountButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.addAccountButton.Size = new System.Drawing.Size(80, 24);
			this.addAccountButton.TabIndex = 24;
			this.addAccountButton.Text = "Add Account";
			this.addAccountButton.Click += new System.EventHandler(this.addConsumerButton_Click);
			// 
			// cancelButton
			// 
			this.cancelButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(224)), ((System.Byte)(223)), ((System.Byte)(227)));
			this.cancelButton.DefaultScheme = true;
			this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.cancelButton.Hint = "";
			this.cancelButton.Location = new System.Drawing.Point(144, 160);
			this.cancelButton.Name = "cancelButton";
			this.cancelButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.cancelButton.Size = new System.Drawing.Size(80, 24);
			this.cancelButton.TabIndex = 25;
			this.cancelButton.Text = "Cancel";
			this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
			// 
			// AddAccountDialog
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(282, 200);
			this.Controls.Add(this.cancelButton);
			this.Controls.Add(this.addAccountButton);
			this.Controls.Add(this.AcctBalancetextBox2);
			this.Controls.Add(this.AcctNametextBox1);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.Limitlabel4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.Label1);
			this.Controls.Add(this.WebsitetextBox1);
			this.Controls.Add(this.CreditLimittextBox1);
			this.Controls.Add(this.Websitelabel5);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "AddAccountDialog";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Add new account";
			this.Load += new System.EventHandler(this.AddAccountDialog_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void label4_Click(object sender, System.EventArgs e)
		{
		
		}

		private void AddAccountDialog_Load(object sender, System.EventArgs e)
		{
		
		}

		private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(comboBox1.SelectedItem == "Bank Account")
			{
				WebsitetextBox1.Show();
				Websitelabel5.Show();
				Limitlabel4.Hide();
				CreditLimittextBox1.Hide();
			}
			if(comboBox1.SelectedItem == "Credit Card")
			{
				Limitlabel4.Show();
				CreditLimittextBox1.Show();
				WebsitetextBox1.Hide();
				Websitelabel5.Hide();
			}
		}

		private void addConsumerButton_Click(object sender, System.EventArgs e)
		{
            // Form validation Issue 109 fix
            decimal accBalance;
            if (!decimal.TryParse(this.AcctBalancetextBox2.Text, out accBalance))
            {// Show error message if garbage was entered for account balance
                DialogResult errorboxResult = MessageBox.Show("Please enter a valid account balance","Invalid Account Balance", MessageBoxButtons.OK,MessageBoxIcon.Error);
                // If ok was clicked, ignore this operation
                return;
            }

            // Store data
			if(comboBox1.SelectedItem == "Bank Account")
			{
				Model.BankAccount acct = new Model.BankAccount(this.AcctNametextBox1.Text,manager.CurrentUserID.Name,this.WebsitetextBox1.Text);
                acct.Balance = accBalance;

				manager.AddNewAccount(acct);
			}
			else
			{
				if(comboBox1.SelectedItem == "Credit Card")
				{
					Model.CreditCard acct = new Model.CreditCard(this.AcctNametextBox1.Text,manager.CurrentUserID.Name,decimal.Parse(this.CreditLimittextBox1.Text));
					acct.Balance=decimal.Parse(this.AcctBalancetextBox2.Text);
					manager.AddNewAccount(acct);
				}
				else
				{
					MessageBox.Show("Please Select Account Type");
				}
			}
			this.Dispose();
		}

		private void cancelButton_Click(object sender, System.EventArgs e)
		{
			this.Dispose();
		}
		
	}
}
